/*
 * Copyright (c) 2007 Compl Yue Still, All Rights Reserved.
 */

package hbi.as3
{
	import flash.utils.IDataInput;
	import flash.utils.IDataOutput;
	
	public class Long
	{
		
		private var _high:int;
		private var _low:uint;
		
		public function Long(value:Number=0)
		{
			if(value != 0)
			{
				this._high = int(value / 0x100000000);
				this._low = uint(value & 0xFFFFFFFF);
			}
		}
		
		public static function readFrom(source:IDataInput):Long
		{
			var n:Long = new Long();
			n._high = source.readInt();
			n._low = source.readUnsignedInt();
			return n;
		}
		
		public function setValue(high:int, low:uint):void
		{
			this._high = high;
			this._low = low;
		}
		
		public function writeTo(target:IDataOutput):void
		{
			target.writeInt(_high);
			target.writeUnsignedInt(_low);
		}
		
		public function get high():int
		{
			return _high;
		}
		
		public function get low():uint
		{
			return _low;
		}
		
		public function uintValue():uint
		{
			return _low;
		}
		
		public function valueOf():Number
		{
			return (_high*0x100000000) + _low;
		}
		
		public function toString():String
		{
			return valueOf().toString();
		}
		
	}
}
